<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2018/8/2
 * Time: 11:02
 */

namespace app\home\model;


use think\Model;

class Mechanism extends Model
{
    /**
     * 机构列表&机构详情
     * @param string $mechanismID 机构ID
     * @param string $field 查询的字段
     * @param $page  分页页数
     * @return array|false|\PDOStatement|string|\think\Collection|Model
     */
    public function mechanismInfo($mechanismID = '', $field = '*', $page = '')
    {
        if($mechanismID == '') {//查列表
            $pageNum = $page - 1;
            $info = $this->field($field)
                ->where('mechanism_status', 2)
                ->order('mechanism_sort desc')
                ->limit($pageNum * 10, 10)
                ->select();
        } else {//查详情
            $info = $this->where('mechanism_id', $mechanismID)
                ->field($field)
                ->find();
        }
        return $info;
    }
    
    /**
     * 获取所有机构的名称
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getMechanismList($name = '', $page = '',$type=1){
        $list =array();
        if($type==1){
            $list = $this->field('mechanism_id, mechanism_name')
                ->where('mechanism_status', 2)
                ->select();
        }else if($type==2){
            $pageNum = $page - 1;
            $list = $this->field('mechanism_id, mechanism_name, mechanism_intro, mechanism_logo')
                ->where('mechanism_name', 'like', "%".$name."%")
                ->where('mechanism_status', 2)
                ->order('mechanism_sort desc')
                ->limit($pageNum * 20, 20)
                ->select();
        }
        return $list;
    }
}